package fun.qu_an.minecraft.mini_games_helper.client.mixin.iris;

import fun.qu_an.minecraft.mini_games_helper.client.handle.ForceOptionHelperSodium;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.server.ServerResourcePackLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.concurrent.CompletableFuture;

@Mixin(ServerResourcePackLoader.class)
public class ServerResourcePackLoaderIrisMixin {
	@Redirect(method = "reload(Lnet/minecraft/client/resource/server/ReloadScheduler$ReloadContext;)V",
		at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;reloadResources()Ljava/util/concurrent/CompletableFuture;"))
	private CompletableFuture<Void> afterLoadServerRP(MinecraftClient instance) {
		return instance.reloadResources().thenRun(() -> {
			if (instance.interactionManager != null) {
				ForceOptionHelperSodium.applyServerRPShader(instance.interactionManager.getCurrentGameMode());
			}
		});
	}
}
